<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\CoRotation;
use App\Admin\Repositories\CoSchool;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Controllers\AdminController;
use Illuminate\Http\Request;

class CoSchoolController extends AdminController
{
    protected $title = '学校管理';
    protected $id;
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new CoSchool(), function (Grid $grid) {
            $grid->id->sortable();
            $grid->name;
//            $grid->lat;
//            $grid->lng;
            $grid->range;
            $grid->seat_time;
            $grid->stop_time;
            $grid->status->switch();
            $grid->created_at;
            $grid->updated_at->sortable();;
//            $grid->withBorder();
//            $grid->disableActions();
//            $grid->disableBatchDelete();
//            $grid->disableCreateButton();
//            $grid->filter(function (Grid\Filter $filter) {
//                $filter->scope(1, admin_trans_field('month'))->where('date', 2019, '<=');
//                $filter->scope(2, admin_trans_label('quarter'))->where('date', 2019, '<=');
//                $filter->scope(3, admin_trans_label('year'))->where('date', 2019, '<=');
//                $filter->equal('content');
//                $filter->equal('cost');
//            });
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->between('created_at', '创建时间')->datetime();
            });
            $grid->actions(function (Grid\Displayers\Actions $actions) {
//                // 当前行的数据数组
//                $rowArray = $actions->row->toArray();

//                // 当前行的某个字段的数据
//                $id = $actions->row->id;

                // 获取当前行主键值
                $id = $actions->getKey();
                // append一个操作
                $actions->append('<a href="/admin/coRotation?school_id='.$id.'"><i class="fa fa-eye">轮播广告</i></a>');
                $actions->append('<a href="/admin/coWeight?school_id='.$id.'"><i class="fa fa-eye">重量价格</i></a>');
                $actions->append('<a href="/admin/coSchoolBuilding?school_id='.$id.'"><i class="fa fa-eye">楼栋管理</i></a>');
                $actions->append('<a href="/admin/coSchoolExpress?school_id='.$id.'"><i class="fa fa-eye">快递点管理</i></a>');
                $actions->append('<a href="/admin/coSchoolTime?school_id='.$id.'"><i class="fa fa-eye">学校时间管理</i></a>');
            });
            $grid->disableViewButton();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new CoSchool(), function (Show $show) {
            $show->id;
            $show->lat;
            $show->lng;
            $show->name;
            $show->range;
            $show->seat_time;
            $show->stop_time;
            $show->status;
            $show->created_at;
            $show->updated_at;
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new CoSchool(), function (Form $form) {
            $form->display('id');
            $form->text('name')->required();
            $form->map('lat', 'lng', '学校位置');
//            $form->text('lat');
//            $form->text('lng');
            $form->radio('status')->options(['0'=>"禁用",'1'=>'启用'])->default(0);
            $form->number('range')->default(5)->required();
            $form->datetime('seat_time')->format('HH:mm:ss')->required();
            $form->datetime('stop_time')->format('HH:mm:ss')->required();
            $form->display('created_at');
            $form->display('updated_at');
            $form->disableViewButton();
            $form->disableDeleteButton();
        });
    }
}
